#
# @lc app=leetcode.cn id=144 lang=python3
#
# [144] 二叉树的前序遍历
#
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
from typing import Optional
from typing import List
# @lc code=start
# Definition for a binary tree node.


class Solution:
    def preorderTraversal(self, root: Optional[TreeNode]) -> List[int]:
        arr = []
        self.preorder(root, arr)
        return arr

    def preorder(self, root: TreeNode, arr: List[int]) -> None:
        if root is None:
            return 
        arr.append(root.val)
        self.preorder(root.left, arr)
        self.preorder(root.right, arr)
# @lc code=end

